import { Component, OnInit, ViewChild } from '@angular/core';
import { Http} from '@angular/http';
import { HttpRequest } from "../../../../service/httpRequest";
import { HideElementService } from "../../../../service/hideElement.service";
import { ActivatedRoute } from '@angular/router';
import { PageModel } from "../../../../model/page-model";
import { flyIn } from '../../../../animations/fly-in';
import { GlobalVariable } from '../../../../global.config'
import { ValuesPipe } from "../../../../pipe/iterable.pipe";
import { FileLoader } from "../../../../service/fileLoader";
declare var $:any;
@Component({
  selector: 'point',
  templateUrl: './point.component.html',
  styleUrls: ['./point.component.css'],
  animations: [
    flyIn
  ]
})
export class PointComponent implements OnInit {
  productId:string = '';
  tool = GlobalVariable.tooltip;
  data:any;
  list = [];
  division:any;
  pageModel = new PageModel();
  page:number = 1;
  propertyData:any;
 
  constructor(private http:Http,private activeRoute: ActivatedRoute,private fileLoader:FileLoader,private httpRequest:HttpRequest,private he:HideElementService) {
    
  }

  ngOnInit() {
    this.fileLoader.LoadFileList(['assets/js/uploadify/jquery.uploadify.min.js'], ()=>{
        $('#file_upload').uploadify({   
          'swf'      : 'assets/js/uploadify/uploadify.swf',
          'uploader' : "http://101.37.24.73:8080/fileupload/property",
          'buttonText': '上传数据点.xls',
          'fileObjName' : 'file',
          'fileTypeDesc' : '选择文件',
          'fileTypeExts' : '*.xlsx;*.xls',
          'method' : 'post',        
          'fileSizeLimit':'10MB',
          'auto' : true,
          'multi' : false,
          'onUploadStart': (file) =>{
              $('#file_upload').uploadify('settings', 'formData', {
                  'product_id': this.productId
              });
          },
          'onUploadSuccess' : (file,data,response)=>{ 
            let filedata = JSON.parse(data);
            $("#file_uploadedponit1").val(filedata.file_path);
            $("#file_uploadedponit").text(filedata.file_path+"上传完成");
            if(response==true){
              this.getProperty();
            }
            
          }        
      });
    });
    this.activeRoute.params.subscribe(
      params=>{
        this.productId = params['productId'];
       
        
      }
    );
    //this.initUploader();
    this.getProperty();
  }

  getProperty(){    
    this.httpRequest.sendGet('product/property/page/'+this.productId,{ 
      'page': this.page,
      'size': this.pageModel.itemsPerPage,
    }).subscribe(res => {      
      this.propertyData = res.result.aaData;
      console.log(this.propertyData)  
      this.pageModel.setPage({'iTotalRecords':res.result.iTotalRecords});      
    },err => console.log(err));
  }

  choseshowids(){
     let showids = "";
     let notshowids = "";

  }

}
